package server;


import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Map;

import entry.Entry;

public class Model {

	private static Model singleton = null;

	/*
	 * A mapping of a filename to an IP address.
	 */
	public final Hashtable<String, Entry> items = new Hashtable<String, Entry>();

	protected Model() {

	}

	public ArrayList<Entry> search(String query, String filterOut) {
		query = query.toLowerCase();

		ArrayList<Entry> list = new ArrayList<Entry>();
		if (query != null) {
			for (Map.Entry<String, Entry> e : items.entrySet()) {
				String s = e.getKey();
				Entry t = e.getValue();

				int foundIndex = s.toLowerCase().indexOf(query);

				if (foundIndex >= 0 && !t.key.equalsIgnoreCase(filterOut)) {
					list.add(new Entry(s, t.value));
				}
			}
		}
		return list;
	}

	public static Model getInstance() {
		if (singleton == null) {
			singleton = new Model();
		}
		return singleton;
	}

}
